package com.atguigu.admin.controller;

import com.atguigu.admin.bean.User;
import com.atguigu.admin.exception.UserTooManyException;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Arrays;
import java.util.List;

/**
 * @author anan
 * @create 2021-08-25 20:25
 */
@Controller
public class TableController {
    @GetMapping("basic_table")
    public String basic_table(@RequestParam("a") Integer a){
        return "table/basic_table";
    }

    @GetMapping("dynamic_table")
    public String dynamic_table(Model model){
        List<User> users = Arrays.asList(new User("1","1111"),
                new User("2", "2222"),
                new User("3", "3333"),
                new User("4","4444"));

        model.addAttribute("users",users);
        if (users.size() > 3){
            throw new UserTooManyException("用户太多了");
        }
        return "table/dynamic_table";
    }

    @GetMapping("editable_table")
    public String editable_table(){
        return "table/editable_table";
    }

    @GetMapping("pricing_table")
    public String pricing_table(){
        return "table/pricing_table";
    }

    @GetMapping("responsive_table")
    public String responsive_table(){
        return "table/responsive_table";
    }

}
